package org.wendu.wdoa.common;

import lombok.extern.slf4j.Slf4j;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.wendu.wdoa.common.ex.BusinessException;
import org.wendu.wdoa.common.ex.TokenException;

@Slf4j
@RestControllerAdvice //用于拦截Controller异常的统一异常处理
public class WdoaControllerAdvice {

    @ExceptionHandler(Exception.class)//声明该方法用于处理controller抛出的Exception异常
    public Result handleException(Exception e){
        log.error("系统错误",e);
        return Result.err(Result.CODE_ERR_SYS,"系统升级中...");
    }

    @ExceptionHandler(BusinessException.class)
    public Result handleBusinessException(BusinessException e){
        return Result.err(Result.CODE_ERR_BUSINESS,e.getMessage());
    }

    @ExceptionHandler(TokenException.class)
    public Result handleTokenException(TokenException e){
        return Result.err(Result.CODE_ERR_UNLOGINED,e.getMessage());
    }


}
